<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../static/教师端.css">
    <link rel="stylesheet" href="../static/iconfont/iconfont.css">
    <title>任教课程</title>
</head>
<body>
<div class="head">
    <div class="header">&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;<img width=36 height=36 src="../static/xh.png"/><img width=180 height=36 src="../static/wz.png"/>
        <a href="/teacher/login" class="exit"><i class="iconfont icon-tuichu"></i>退出登录</a></div>
</div>
<div class="big_box">
    <div class="wrap">
        <div class="seg"></div>
        <div class="item_title">
            <b>教师端</b>
        </div>
        <div class = "seg"></div>
        <div class="item">
            <a href="http://localhost:8080/teacher/tutorial"><i class="iconfont icon-yixuan" ></i>&ensp;任教课程</a>
        </div>
        <div class="item">
            <a href="http://localhost:8080/teacher/up_course"><i class="iconfont icon-fabu" ></i>&ensp;发布课程</a>
        </div>
        <div class="item">
            <a href="http://localhost:8080/teacher/modify_course"><i class="iconfont icon-xiugai" ></i>&ensp;修改课程</a>
        </div>
        <div class="item">
            <a href="http://localhost:8080/teacher/delete_course"><i class="iconfont icon-shanchu" ></i>&ensp;删除课程</a>
        </div>
        <div class="item">
            <a href="教师个人信息"><i class="iconfont icon-gerenxinxi" ></i>&ensp;个人信息</a>
        </div>
    </div>
<div class="main">
    <div class="row">
        <h1>
            我的任教课程
        </h1>
        <div class="selected">
            <form action="/renjiao_search" method="post" >
                请选择类别&nbsp;
                <select class="classification" id="classification" onchange=selected() style="color: #295287;">
                    <option value="1-1">公共课</option>
                    <option value="1-2">专业课</option>
                    <option value="2-1">通识课</option>
                </select>
                <input type="button" class="button" value="检索" onclick="search()"/>
            </form>
        </div>
        <div class="course_table" id="course_table" style="display: none">
            <table id="table" class="table" >
                <thead>
                <tr>
                    <th>课程号</th>
                    <th>课程名</th>
                    <th>课程时长</th>
                    <th>课程学分</th>
                    <th>上课时间</th>
                    <th>上课地点</th>
                    <th>可选人数</th>
                    <th>课程类别</th>
                    <th>授课教师</th>
                    <th>学生查看</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
</div>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
    function selected(){
        var vs=$('select option:selected').val();
        var show_table=document.querySelector('.table');
        // show_table.style.display='block';
    }
    function search(){
        document.getElementById("course_table").style.display="block";
        var select=document.getElementById("classification");
        var classify=select.value;
        $.ajax({
            type: "POST",
            url: "/teacher/ututorial",
            data:{"classify_id":classify},
            dataType: "json",
            success: function (dat) {
                if(dat.c_count==0) {
                    var ltr = '<tr><th>您暂未发布此类课程!</th></tr>';
                    $("table").empty();
                    $("table").append(ltr);
                }
              //  window.location.href="http://localhost:8080/teacher/tutorial";
                else{
                    var ltr='<tr><th>'+"课程号"+
                        '</th><th>'+"课程名"+
                        '</th><th>'+"课程时长"+
                        '</th><th>'+"课程学分"+
                        '</th><th>'+"上课时间"+
                        '</th><th>'+"上课地点"+
                        '</th><th>'+"可选人数"+
                        '</th><th>'+"课程类别"+
                        '</th><th>'+"授课老师"+
                        '</th><th>'+"学期"+
                        '</th><th>'+"操作"+
                        '</th></tr>';
                    var course_th=dat.course_th;
                    $.each(course_th,function(index,course){
                        var term;
                        if(course.term=="1"){term="大一上学期"}
                        else if(course.term=="2"){term="大一下学期"}
                        else if(course.term=="3"){term="大二上学期"}
                        else if(course.term=="4"){term="大二下学期"}
                        else if(course.term=="5"){term="大三上学期"}
                        else if(course.term=="6"){term="大三下学期"}
                        var tr='<tr><td>'+course.courseid+
                            '</td><td>'+course.coursename+
                            '</td><td>'+course.coursetime+
                            '</td><td>'+course.coursescore+
                            '</td><td>'+course.time+
                            '</td><td>'+course.site+
                            '</td><td>'+course.number+
                            '</td><td>'+course.classify+
                            '</td><td>'+course.teacher+
                            '</td><td>'+term+
                            '</td><td><button id="button_s" value="'+course.courseid+
                            '" class="button" style="background-color:#308ad9;border: 3px solid #308ad9;" onclick="search_cs(this)">查看学生 </button></td></tr>';
                        ltr=ltr+tr;
                        //document.getElementById("button_s").value=course.courseid;
                    })
                    $("table").empty();
                    $("table").append(ltr);
                }
            },
            error : function (XMLHttpRequest, textStatus, errorThrown) {
                console.log("错误");
                // 状态码
                console.log(XMLHttpRequest.status);
                // 状态
                console.log(XMLHttpRequest.readyState);
                // 错误信息
                console.log(textStatus);
            }
            }
        )

    }
    //发送当前课程号，用于检索所选课程的学生
    function search_cs(self){
        $.ajax({
            type:'POST',
            url:'/teacher/uc_student',
            data:{
                "course_id":self.getAttribute('value')
            },
            dataType:"json",
            success:function(dat){
               if(dat.count==0){
                   alert("暂无学生！");
               }else{
                   window.location.href="http://localhost:8080/teacher/c_student";
               }
            },
            error : function (XMLHttpRequest, textStatus, errorThrown) {
                console.log("错误");
                // 状态码
                console.log(XMLHttpRequest.status);
                // 状态
                console.log(XMLHttpRequest.readyState);
                // 错误信息
                console.log(textStatus);
            }
        })
    }
    function logout(){
            $.ajax({
            async:false,
            type:"post",
            url:'/logout',
            contentType:"application/x-www-form-urlencoded;charset=utf-8",
            dataType:"text",
            complete:function(){
                window.location.reload();
            }
        })
    }
</script>
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.24/assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.24/dist/js/bootstrap.min.js"></script>
<!-- Just to make our placeholder images work. Don't actually copy the next line! -->
<script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.24/assets/js/vendor/holder.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.24/assets/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>